<?php include incTemplate('header');?>
<link rel="stylesheet" href="<?php echo HH;?>js/jquery.plugin/fancybox/jquery.fancybox-1.3.4.css">
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script type="text/javascript" src="<?php echo HH;?>js/jquery.plugin/AjaxFileUploader/ajaxfileupload.js"></script>
<script type="text/javascript">
$(function(){

	$(".tbimg").hover(
	  function () {
	    $(this).css("background-color","#FBEC88");
	  },
	  function () {
		 $(this).css("background-color","");
	  }
	);
	
	$("a[rel=certimg]").fancybox();

	$("#addcert").click(function(){
	    $('#win_add').window({  
	        modal:true,
	        width:350,
	        height:180,
	        draggable:false,
	        minimizable:false,
	        maximizable:false,
	        collapsible:false
	    });  
	});
	
	$("#updatecert").click();

	$("#deletecert").click(function(){
		var carts = $("input:checkbox");
		var checked = false;
		var cartslist = new Array();
		carts.each(function(i){
			var ck = $(this).attr("checked");
			if(ck){
				checked = true;
				cartslist.push($(this).val());
			}
		});

		if(!checked){
			$.messager.alert('提示','请选择证书！'); 
		}else{
			$("#form1").attr("action","/admin.php/cert/deletecert");
			$("#certids").val(cartslist);
			$("#form1").submit();
		}
	});

	$("#btn_add").click(function(){
		var titleval = $("#title").val();
		var certimg = $("#certimg").val();

		if(certimg == ""){
			$.messager.alert('提示','上传图片不能为空！');
			return;
		}
		
		if(!isImg(certimg)){
			$.messager.alert('提示','上传的图片类型不正确！');
			return;
		}
		
		$.ajaxFileUpload
		(
			{
				url:'/admin.php/cert/addcert',
				secureuri:false,
				fileElementId:'certimg',
				dataType: 'json',
				data:{title:titleval},
				success: function (data, status)
				{
					if(data.success==true){
						$.messager.alert('提示','添加成功！');
						window.location.reload();
					}else{
						$.messager.alert('提示','上传时有误！');
					}
				},
				error: function (data, status, e)
				{
					$.messager.alert('异常信息',e);
				}
			}
		)
		
	});

	$("#btn_update").click(function(){
		var titleval = $("#update_title").val();
		var certimg = $("#update_certimg").val();
		
		if(certimg == ""){
			$.messager.alert('提示','上传图片不能为空！');
			return;
		}
		
		if(!isImg(certimg)){
			$.messager.alert('提示','上传的图片类型不正确！');
			return;
		}
		
		$.ajaxFileUpload
		(
			{
				url:'/admin.php/cert/updatecert',
				secureuri:false,
				fileElementId:'update_certimg',
				dataType: 'json',
				data:{update_title:titleval,updateid:$("#updateid").val()},
				success: function (data, status)
				{
					if(data.success==true){
						$.messager.alert('提示','修改成功！');
						window.location.reload();
					}else{
						$.messager.alert('提示','上传时有误！');
					}
				},
				error: function (data, status, e)
				{
					$.messager.alert('异常信息',e);
				}
			}
		)
	});

});
function updatecert(certid){
	$("#updateid").val(certid);

    $('#win_update').window({  
        modal:true,
        width:350,
        height:180,
        draggable:false,
        minimizable:false,
        maximizable:false,
        collapsible:false
    });  
	
}
</script>
</head>
<body class="body" >

<div class="hidden">
<div id="win_add" title="添加证书">
<table class="tab_form" style="margin-top:20px;" >
	<tr>
		<td class="edit_td" width="80px">名称：</td><td class="rig_td">
		<input type="text" name="title" class="easyui-validatebox" required="true" id="title" class="w_200" />
		</td>
	</tr>
	<tr>
		<td class="edit_td">图片：</td><td class="rig_td">
		<input type="file" name="certimg" id="certimg" />
		</td>
	</tr>
	<tr>
		<td></td>
		<td><input id="btn_add" type="button" value="添加证书"/></td>
	</tr>
</table>
</div>

<div id="win_update" title="修改证书">
<input type="hidden" name="updateid" id="updateid" />
<table class="tab_form" style="margin-top:20px;" >
	<tr>
		<td class="edit_td" width="80px">名称：</td><td class="rig_td">
		<input type="text" name="update_title" class="easyui-validatebox" required="true" id="update_title" class="w_200" />
		</td>
	</tr>
	<tr>
		<td class="edit_td">图片：</td><td class="rig_td">
		<input type="file" name="update_certimg" id="update_certimg" />
		</td>
	</tr>
	<tr>
		<td></td>
		<td><input id="btn_update" type="button" value="修改证书"/></td>
	</tr>
</table>
</div>

</div>



<form action="" method="post" id="form1">
<input type="hidden" name="certids" id="certids" />
<div style="padding:5px;background:#efefef;" class="mgb_10">
	<a class="easyui-linkbutton" plain="true" iconCls="icon-add" id="addcert">添加证书</a>
	<a class="easyui-linkbutton" plain="true" iconCls="icon-cut" id="deletecert">删除证书</a>
</div> 

<table width="100%" class="tablist" >
<thead>
	<tr>
		<td width="6%">序号</td><td width="3%">选择</td><td width="25%">标题</td><td>路径</td><td width="25%"></td>
	</tr>
</thead>
<tbody>
<?php 
$i = 1;
foreach ($certs as $cert){
	?>
		<tr>	
		<td><?php echo $i;?></td>
		<td><input name="certids" type="checkbox" value="<?php echo $cert['id'];?>"/></td>
	<td><?php echo $cert['title']?></td><td><a  rel="certimg" href="/<?php echo $cert['location'];?>"><?php echo $cert['location']?></a></td>
	<td><a href="javascript:updatecert(<?php echo $cert['id'];?>)">修改证书</a></td>
	</tr>
	<?php
	$i ++;
}
?>
</tbody>
</table>
</form>
</body>
</html>